<template>
  <ConfigProvider :locale="zh_CN">
    <router-view></router-view>
  </ConfigProvider>
</template>

<script>
import { ConfigProvider } from 'ant-design-vue';

import zh_CN from "ant-design-vue/lib/locale-provider/zh_CN";
// import zhCN from 'ant-design-vue/es/locale/zh_CN'   // 在node_modules中找到（可切换各种语言）
import moment from "moment";
import "moment/locale/zh-cn";
import storage from 'store';
import {mapGetters} from "vuex";
import {storeUpkeep} from "@/api/store";

moment.locale("zh-cn");

export default {
  name: "App",
  components: {ConfigProvider},
  data() {
    return {
      zh_CN,
      list: '',
    };
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  created() {
    setTimeout(()=>{
      this.getStoreUpkeep()
    },500)
  },
  methods: {
    getStoreUpkeep(){
      console.log(this.userInfo.type,'userInfotype')
      if(this.userInfo.type === 3){
        console.log(storage.get('today'))
        //if(storage.get('today') == new Date().getFullYear() + '-' + (new Date().getMonth()+1) + '-' + new Date().getDate()){

        //}else{
        storeUpkeep(/*{
          name: 'iec国际企业中心'
        }*/)
          .then(res => {
            this.list = res.data;
            if (this.judge(res.data.upkeep_time)){
              this.tip();
            }
          })
        //}
      }
    },
    tip(){
      this.$confirm({
        title: '缴费提示',
        content: '您有新的系统维护费待缴纳',
        onOk: () => {
          storage.set('today', new Date().getFullYear() + '-' + (new Date().getMonth()+1) + '-' + new Date().getDate())
          this.$router.push({
            name: 'clothesOrder',
            params: { store_id: this.list.id }
          })
        },
        onCancel: ()=> {
          storage.set('today', new Date().getFullYear() + '-' + (new Date().getMonth()+1) + '-' + new Date().getDate())
        },
      })
    },
    judge(date){
      // 获取当前日期
      const targetDate = new Date(date);
      if(targetDate==null) return false;
      const currentDate = new Date();
      // 将当前日期与指定日期相减，得到相差的天数
      const diffDays = Math.ceil((targetDate.getTime() - currentDate.getTime()) / (1000 * 60 * 60 * 24));
      // 判断相差的天数是否在0到30之间
      if (diffDays >= 0 && diffDays <= 30) {
        return diffDays;
      }else {
        return false;
      }
    },
  }
};
</script>
<style>
	.ant-pro-basicLayout-content .ant-pro-page-header-wrap{
		margin:0!important;
	}
	.ant-pro-basicLayout-content{
		margin:0!important;
	}
</style>